package com.study.action;

import com.opensymphony.xwork2.ActionSupport;

public class BookAction extends ActionSupport {
    private String message;
    private int pageNow = 1;
    private int pageSize = 4;
    private File photo;
    private Book book;
    BookService bookservice;
    LendService lendservice;

    //省略上面属性的get和set方法
    public String addBook() throws Exception {
        if (bookservice.selectBook(book.getISBN()) != null) {
            this.setMessage("该ISBN的图书已经存在！");
            return SUCCESS;
        }
        Book b = new Book();
        b.setISBN(book.getISBN());
        b.setBookName(book.getBookName());
        b.setAuthor(book.getAuthor());
        b.setPublisher(book.getPublisher());
        b.setPrice(book.getPrice());
        b.setCnum(book.getCnum());
        b.setSnum(book.getCnum());
        b.setSummary(book.getSummary());
        if (this.getPhoto() != null) {
            FileInputStream fis = new FileInputStream(this.getPhoto());
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            b.setPhoto(buffer);
        }
        bookservice.addBook(b);
        this.setMessage("添加成功！");
        return SUCCESS;
    }
}
